#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author： 胡浩浩
# datetime： 2021/12/28 15:45 
# ide： PyCharm
from sqlalchemy.orm import Session
from Models.assetModel import asset_model
from Schemas.assetSchema import asset_schema


def get_asset_by_id(db: Session, asset_id: int):
    return db.query(asset_model.Asset).filter(asset_model.Asset.id == asset_id).first()


def get_asset_list(db: Session, skip: int = 0, limit: int = 10):
    return db.query(asset_model.Asset).offset(skip).limit(limit).all()


def create_asset(db: Session, asset: asset_schema.AssetCreate):
    db_asset = asset_model.Asset(**asset.dict())
    db.add(db_asset)
    db.commit()
    db.refresh(db_asset)
    return db_asset
